<%@ include file="/includes.jsp" %>
<%@ include file="/header.jsp" %>

<c:if test="${event.administrator.id}.equals${session.user.id}">
    <c:set var="readonly" value="false"/>
</c:if>
<c:if test="!${event.administrator.id}.equals${session.user.id}">
    <c:set var="readonly" value="true"/>
</c:if>


<c:choose>
    <c:when test="${event.administrator} != ${session.user}">
        <h2>Position Details</h2>
    </c:when>
    <c:when test="${position.new}">
        <h2>Add Position</h2>
    </c:when>
    <c:otherwise>
        <h2>Update position</h2>
    </c:otherwise>
</c:choose>

<form:form modelAttribute="position">
    <table>
        <tr>
            <td>Position Name:</td>
            <td><form:input path="name" size="30" maxlength="30"/></td>
            <td><form:errors path="name" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Position Description:</td>
            <td><form:textarea path="description" cols="30"/></td>
            <td><form:errors path="description" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Location:</td>
            <td><form:input path="location" size="30" maxlength="80"/></td>
            <td><form:errors path="location" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Count:</td>
            <td><form:input path="count" size="10" maxlength="10"/></td>
            <td><form:errors path="count" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Start time:</td>
            <td><form:input path="startTime" size="20" maxlength="20"/> [MM.dd.yy HH:mm]</td>
            <td><form:errors path="startTime" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>End time:</td>
            <td><form:input path="endTime" size="20" maxlength="20"/> [MM.dd.yy HH:mm]</td>
            <td><form:errors path="endTime" cssClass="errors"/></td>
        </tr>
        <tr>
            <td colspan="3">
                <c:choose>
                    <c:when test="${position.new}">
                        <p class="submit"><input type="submit" value="Add Position"/></p>
                    </c:when>
                    <c:otherwise>
                        <p class="submit"><input type="submit" value="Update Position"/></p>
                    </c:otherwise>
                </c:choose>
            </td>
        </tr>
    </table>
</form:form>

<table width="100%">
    <thead align="left">
    <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Remove</th>
    </tr>
    </thead>
    <c:if test="${empty position.volunteers}">
        <tr>
            <td colspan="3">
                No volunteers for this position.
            </td>
        </tr>
    </c:if>
    <c:if test="${not empty position.volunteers}">
        <c:forEach var="user" items="${position.volunteers}">
            <tr>
                <td width="*">${user.lastName}, ${user.firstName}</td>
                <td>${user.email}</td>
                <td>
                    <form method="GET" action="<c:url value="../position/unvolunteer"/>" name="unvolunteer">
                        <input type="hidden" name="eventId" value="${position.eventId}"/>
                        <input type="hidden" name="id" value="${position.id}"/>
                        <input type="hidden" name="volunteerId" value="${user.id}"/>
                        <input class="submit" type="submit" value="Remove"/>
                    </form>
                </td>
            </tr>
        </c:forEach>
    </c:if>
</table>


<%@ include file="../footer.jsp" %>